package com.hl.web;

import com.hl.pojo.Coursefavorites;
import com.hl.pojo.Mycoursefavorites;
import com.hl.service.CourseFavoriteService;
import com.hl.util.GeneralResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/favorite")
public class CourseFavoriteController {
    @Autowired
    private CourseFavoriteService courseFavoriteService;
    @RequestMapping("/getCourseFavoriteNoPaid")
    public GeneralResult getCourseFavoriteNoPaid(@RequestBody Map<String,Integer> map){
        Integer id = map.get("id");
        System.out.println(id);
        List<Mycoursefavorites> list = courseFavoriteService.getCourseFavoriteNoPaid(id);
        System.out.println(list);
        return GeneralResult.success(list);
    }
    @RequestMapping("/getCourseFavoriteIsPaid")
    public GeneralResult getCourseFavoriteIsPaid(@RequestBody Map<String,Integer> map){
        Integer id = map.get("id");
        System.out.println(id);
        List<Mycoursefavorites> list = courseFavoriteService.getCourseFavoriteIsPaid(id);
        System.out.println(list);
        return GeneralResult.success(list);
    }

    @RequestMapping("/SelectCourseFavoriteListAll")
    public GeneralResult SelectCourseFavoriteListAll(){
        List<Mycoursefavorites> list = courseFavoriteService.SelectCourseFavoriteListAll();
        return GeneralResult.success(list);
    }

    @RequestMapping("/UpdateCourseFavoriteList")
    public GeneralResult UpdateCourseFavoriteList(@RequestBody Map<String,Object> map){
        Integer favoriteId = (Integer) map.get("favoriteId");
        Integer isPaid = (Integer) map.get("isPaid");
        System.out.println("********************"+favoriteId+"***"+isPaid);
        Mycoursefavorites mycoursefavorites = new Mycoursefavorites();
        mycoursefavorites.setFavoriteId(favoriteId);
        mycoursefavorites.setIsPaid(isPaid);
        System.out.println(courseFavoriteService.UpdateCourseFavoriteList(mycoursefavorites));
        return GeneralResult.success("请求成功",courseFavoriteService.UpdateCourseFavoriteList(mycoursefavorites));
    }
}
